package com.dmzapp.cashoffer.customview;

import android.content.Context;
import android.util.AttributeSet;
import android.view.GestureDetector.OnGestureListener;
import android.view.MotionEvent;
import android.view.animation.AnimationUtils;
import android.widget.ViewFlipper;

import com.huluwa.dmzapp.cashoffer.R;

public class PicFlingView extends ViewFlipper implements OnGestureListener{
    private Context context;
    public PicFlingView(Context context) {
        super(context);
       
        init(context);
    }

    public PicFlingView(Context context, AttributeSet ar) {
        super(context, ar);
        init(context);
    }

    private void init(Context context) {
        this.context = context;
    }

    @Override
    public boolean onDown(MotionEvent e) {
        // TODO Auto-generated method stub
        return false;
    }

    @Override
    public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {
        return false;
    }

    @Override
    public void onLongPress(MotionEvent e) {
        // TODO Auto-generated method stub
        
    }

    @Override
    public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float distanceY) {
        // TODO Auto-generated method stub
        return false;
    }

    @Override
    public void onShowPress(MotionEvent e) {
        // TODO Auto-generated method stub
        
    }

    @Override
    public boolean onSingleTapUp(MotionEvent e) {
        // TODO Auto-generated method stub
        return false;
    }
    private float downX;
    @Override
    public boolean onTouchEvent(MotionEvent event) {
        if (event.getAction() == MotionEvent.ACTION_DOWN) {
            downX = event.getX();
        } else if (event.getAction() == MotionEvent.ACTION_UP && downX != 0) {
            if (event.getX() - downX > 5) {
                setInAnimation(AnimationUtils.loadAnimation(context, R.anim.push_right_in));
                setOutAnimation(AnimationUtils.loadAnimation(context, R.anim.push_right_out));
                
                showPrevious();
                
            } else if (event.getX() - downX < -5) {

                setInAnimation(AnimationUtils.loadAnimation(context, R.anim.push_left_in));
                setOutAnimation(AnimationUtils.loadAnimation(context, R.anim.push_left_out));
                
                showNext();
                
            }
            downX = 0;
        }
        
        return true;
    }
}
